package com.suneast.suneaststore.modules.goodsdetail.event;

import android.util.SparseArray;

import com.suneast.suneaststore.bean.goodsdetail.RelativeBean;
import com.suneast.suneaststore.bean.goodsdetail.SpecsDataBean;

import java.util.List;

public class GotSpecsDataEvent {

    private SpecsDataBean data;

    private SparseArray<SparseArray<RelativeBean>> relativeSparses;

    public GotSpecsDataEvent(SpecsDataBean data) {
        this.data = data;
        relativeSparses = generateRelativeBeans(data.getSpecs_group());
    }

    private SparseArray<SparseArray<RelativeBean>> generateRelativeBeans(List<SpecsDataBean.SpecsGroupBean> list) {
        SparseArray<SparseArray<RelativeBean>> sparseArray = new SparseArray<>();
        for (int i = 0, iLength = list.size(); i < iLength; i++) {
            SparseArray<RelativeBean> beanList = new SparseArray<>();
            List<SpecsDataBean.SpecsGroupBean.ItemBean> itemBeanList = list.get(i).getItem();
            for (int j = 0, jLength = itemBeanList.size(); j < jLength; j++) {
                RelativeBean bean = new RelativeBean(
                        Integer.valueOf(itemBeanList.get(j).getId()),
                        itemBeanList.get(j).getLevel());
                beanList.append(bean.getId(), bean);
            }
            sparseArray.append(list.get(i).getId(), beanList);
        }
        return sparseArray;

    }

    public SpecsDataBean getData() {
        return data;
    }

    public SparseArray<SparseArray<RelativeBean>> getRelativeSparses() {
        return relativeSparses;
    }
}
